/*============================================================
 Create Time:			2020-09-04 12:54:59
 Last modify:			2020-09-08 14:41:27
 Writer:				Wenhao	1795902848@qq.com
 File Name:				Send.c
 File Type:				C Source File
 Tool:					Windows -- vim & gcc, gdb
 Information:			Sender main file
============================================================*/
#include <reg52.h>
#include "code.h"
#include "lib.h"
#include "C:\\my_lib\my_lib.h"

#define __TH2 0xff
#define __TL2 0xee

sbit KEY1 = P2^4;			//最左边的按键
sbit KEY2 = P2^5;
sbit KEY3 = P2^6;
sbit KEY4 = P2^7;			//最右边的按键
sbit LED = P1^0;

void init_uart()
{
	T2MOD = 0x00;		//set Timer to bold
	T2CON = 0x30;		//set Timer to bold
	TH2 = __TH2;
	TL2 = __TL2;
	RCAP2H = __TH2;
	RCAP2L = __TL2;
	TR2 = 1;			//start timer2 bold
	SCON = 0x50;
}

void main()
{
	init_uart();
	while(1)
	{
		if(KEY4 == 0)
		{
			delay(70);
			if(KEY4 == 0)
			{
				delay(100);
				if(KEY4 == 0)
				{
					while(!KEY4);
					send_user_data((uint8)(MODE_1));		//长按
				}
				else
					send_user_data((uint8)(MODE_0));		//短按
			}
		}
		else if(KEY3 == 0)
		{
			delay(70);
			if(KEY3 == 0)
			{
				delay(100);
				if(KEY3 == 0)
				{
					while(!KEY3);
					send_user_data((uint8)(MODE_3));		//长按
				}
				else
					send_user_data((uint8)(MODE_2));		//短按
			}
		}
		else if(KEY2 == 0)
		{
			delay(70);
			if(KEY2 == 0)
			{
				delay(100);
				if(KEY2 == 0)
				{
					while(!KEY2);
					send_user_data((uint8)(DEC_DIGIT));		//长按
				}
				else
					send_user_data((uint8)(INC_DIGIT));			//短按
			}
		}
		else if(KEY1 == 0)
		{
			delay(70);
			if(KEY1 == 0)
			{
				delay(100);
				if(!KEY1)
				{
					while(!KEY1);
					send_user_data((uint8)(DEC_LETTER));		//长按
				}
				else
					send_user_data((uint8)(INC_LETTER));			//短按
			}
		}
	}
}
